Java 8 Interview Questions and Answers
Question: What is lambda expression?Answer:Lambda expression is anonymous function which have set of parameters and a lambda (->) and a function body. You can call it function without name. Structure of Lambda Expressions: (Argument List) ->{expression;} or (Argument List) ->{statements;} For instance, the Runnable interface is a functional interface, so instead of: Thread thread = new Thread(new Runnable() { public void run() { System.out.println("Hello World!"); } }); Using Lambda you can simply do the following: Thread thread = new Thread(() -> System.out.println("Hello World!")); Functional interfaces are usually annotated with the @FunctionalInterface annotation - which is informative and does not affect the semantics. |
Is it helpful?
Yes
No
Most helpful rated by users:
- What are new features which got introduced in Java 8?
- What are main advantages of using Java 8?
- Can you explain the syntax of Lambda expression?
- What are functional interfaces?
- What Is a Default Method and When Do We Use It?